﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public DataRow Convert2BAAUF(DataRow dwInput, string AUF, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryABAUFM(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (AUF)
            {
                case "JLT":
                    #region======JLT========
                    dwReturn["BAMANDANT"] = "00";
                    dwReturn["BAAUFTYP"] = "V";
                    dwReturn["BAAUFKRS"] = "T5";
                    dwReturn["BAAUFLFD"] = "001329";
                    dwReturn["BAAUFPOS"] = "001";
                    dwReturn["BASA"] = "733";
                    dwReturn["BAPOS"] = "0001";
                    dwReturn["BAAFOLGE"] = "010";
                    dwReturn["BADATVON"] = "20141126";
                    dwReturn["BADATBIS"] = "20141126";
                    dwReturn["BAKART"] = "J4-0003             ";
                    dwReturn["BAKVAR"] = "1 ";
                    dwReturn["BAKFARBE"] = "1         ";
                    dwReturn["BAMTR1"] = "23450";
                    dwReturn["BAANZ1"] = "1";
                    dwReturn["BAMTR2"] = "0";
                    dwReturn["BAANZ2"] = "0";
                    dwReturn["BAMTR3"] = "0";
                    dwReturn["BAANZ3"] = "0";
                    dwReturn["BAMTR4"] = "0";
                    dwReturn["BAANZ4"] = "0";
                    dwReturn["BAMTR5"] = "0";
                    dwReturn["BAANZ5"] = "0";
                    dwReturn["BAMTR6"] = "0";
                    dwReturn["BAANZ6"] = "0";
                    dwReturn["BAMTR7"] = "0";
                    dwReturn["BAANZ7"] = "0";
                    dwReturn["BAERLKZ"] = " ";
                    dwReturn["BABAUMART"] = "01    ";
                    dwReturn["BADRKZ"] = "0";
                    dwReturn["BADISPOKZ"] = "B";
                    dwReturn["BALO"] = "01";
                    dwReturn["BALB"] = "ZZ";
                    dwReturn["BALP"] = "01      ";
                    dwReturn["BAAUFBKZ"] = " ";
                    dwReturn["BAURKVAR"] = "1 ";
                    dwReturn["BAAENDZL"] = "1";
                    dwReturn["BAAENDBEN"] = "        ";
                    dwReturn["BAAENDDAT"] = "0";
                    dwReturn["BANEUBEN"] = "INTEXE  ";
                    dwReturn["BANEUDAT"] = "20141009";
                    dwReturn["BADOMKZ"] = "D";
                    dwReturn["BABASMG"] = "10000";
                    dwReturn["BALLEIST"] = "    ";
                    dwReturn["BARLEIST"] = "    ";
                    dwReturn["BASCHIENE"] = "     ";
                    dwReturn["BATLPOS"] = "00";
                    dwReturn["BAINFOKZ"] = " ";
                    dwReturn["BAVARKZ"] = " ";
                    dwReturn["BATLSA"] = "   ";
                    dwReturn["BAABF2"] = "0";
                    dwReturn["BAZBEDKG"] = "0";
                    dwReturn["BAZBEDMTR"] = "0";
                    dwReturn["BAFILLER"] = "Z0000 00000000                                   ";

                    #endregion
                    break;
                default:
                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwInput.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapBAAUF(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveBAAUF(DataRow dwData, string ITXDBVERSION)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryBAAUF(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapBAAUF(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertBAAUF(dwLocal);
            }
            UpdateBAAUF(dwLocal);
        }
        public void InsertBAAUF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO BAAUF(BAMANDANT, BAAUFTYP, BAAUFKRS, BAAUFLFD, BAAUFPOS, BASA, BAPOS, BAAFOLGE, BADATVON, BADATBIS, BAKART, BAKVAR, BAKFARBE, BAMTR1, BAANZ1, BAMTR2, BAANZ2, BAMTR3, BAANZ3, BAMTR4, BAANZ4, BAMTR5, BAANZ5, BAMTR6, BAANZ6, BAMTR7, BAANZ7, BAERLKZ, BABAUMART, BADRKZ, BADISPOKZ, BALO, BALB, BALP, BAAUFBKZ, BAURKVAR, BAAENDZL, BAAENDBEN, BAAENDDAT, BANEUBEN, BANEUDAT, BADOMKZ, BABASMG, BALLEIST, BARLEIST, BASCHIENE, BATLPOS, BAINFOKZ, BAVARKZ, BATLSA, BAABF2, BAZBEDKG, BAZBEDMTR, BAFILLER)"
             + " VALUES (:BAMANDANT, :BAAUFTYP, :BAAUFKRS,:BAAUFLFD, :BAAUFPOS, :BASA, :BAPOS, '010', 0, 0, '                    ', '  ', '          ', 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ' ', '      ', '0', 'B', '  ', '  ', '        ', ' ', '1 ', 9, '        ', 0, '        ', 0, 'D', 0, '    ', '    ', '     ', '00', ' ', ' ', '   ', 0, 0, 0, '                                                 ')";
            or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = dwData["BAMANDANT"].ToString();
            or1.Parameters.Add("BAAUFTYP", OracleType.NVarChar).Value = dwData["BAAUFTYP"].ToString();
            or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = dwData["BAAUFKRS"].ToString();
            or1.Parameters.Add("BAAUFLFD", OracleType.Number).Value = dwData["BAAUFLFD"].ToString();
            or1.Parameters.Add("BAAUFPOS", OracleType.NVarChar).Value = dwData["BAAUFPOS"].ToString();
            or1.Parameters.Add("BASA", OracleType.NVarChar).Value = dwData["BASA"].ToString();
            or1.Parameters.Add("BAPOS", OracleType.NVarChar).Value = dwData["BAPOS"].ToString();
            setResult = Connect2Proxy(or1);
        }
        public void DeleteBAAUF(string client, string krs, string lfd, string pos, int option = 1)
        {
            OracleCommand or1 = OracleDB.CreateCommand();

            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM BAAUF WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "DELETE BAAUF "
                + "  WHERE BAMANDANT=:BAMANDANT AND BAAUFKRS=:BAAUFKRS AND BAAUFLFD=:BAAUFLFD AND BAAUFPOS=:BAAUFPOS";
                    or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = client;
                    or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = krs;
                    or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = lfd;
                    or1.Parameters.Add("BAAUFPOS", OracleType.NVarChar).Value = pos;
                    break;
                case 2:
                    or1.CommandText = "DELETE BAAUF "
                + "  WHERE GAMANDANT=:BAMANDANT AND BAAUFKRS=:BAAUFKRS AND BAAUFLFD=:BAAUFLFD ";
                    or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = client;
                    or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = krs;
                    or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = lfd;

                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void UpdateBAAUF(DataRow dwData, string ITXDBVERSION = "50.24", int option = 2)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "UPDATE BAAUF SET "
              + "BAMANDANT=:BAMANDANT,"
              + "BAAUFTYP=:BAAUFTYP,"
              + "BAAUFKRS=:BAAUFKRS,"
              + "BAAUFLFD=:BAAUFLFD,"
              + "BAAUFPOS=:BAAUFPOS,"
              + "BASA=:BASA,"
              + "BAPOS=:BAPOS,"
              + "BAAFOLGE=:BAAFOLGE,"
              + "BADATVON=:BADATVON,"
              + "BADATBIS=:BADATBIS,"
              + "BAKART=:BAKART,"
              + "BAKVAR=:BAKVAR,"
              + "BAKFARBE=:BAKFARBE,"
              + "BAMTR1=:BAMTR1,"
              + "BAANZ1=:BAANZ1,"
              + "BAMTR2=:BAMTR2,"
              + "BAANZ2=:BAANZ2,"
              + "BAMTR3=:BAMTR3,"
              + "BAANZ3=:BAANZ3,"
              + "BAMTR4=:BAMTR4,"
              + "BAANZ4=:BAANZ4,"
              + "BAMTR5=:BAMTR5,"
              + "BAANZ5=:BAANZ5,"
              + "BAMTR6=:BAMTR6,"
              + "BAANZ6=:BAANZ6,"
              + "BAMTR7=:BAMTR7,"
              + "BAANZ7=:BAANZ7,"
              + "BAERLKZ=:BAERLKZ,"
              + "BABAUMART=:BABAUMART,"
              + "BADRKZ=:BADRKZ,"
              + "BADISPOKZ=:BADISPOKZ,"
              + "BALO=:BALO,"
              + "BALB=:BALB,"
              + "BALP=:BALP,"
              + "BAAUFBKZ=:BAAUFBKZ,"
              + "BAURKVAR=:BAURKVAR,"
              + "BAAENDZL=:BAAENDZL,"
              + "BAAENDBEN=:BAAENDBEN,"
              + "BAAENDDAT=:BAAENDDAT,"
              + "BANEUBEN=:BANEUBEN,"
              + "BANEUDAT=:BANEUDAT,"
              + "BADOMKZ=:BADOMKZ,"
              + "BABASMG=:BABASMG,"
              + "BALLEIST=:BALLEIST,"
              + "BARLEIST=:BARLEIST,"
              + "BASCHIENE=:BASCHIENE,"
              + "BATLPOS=:BATLPOS,"
              + "BAINFOKZ=:BAINFOKZ,"
              + "BAVARKZ=:BAVARKZ,"
              + "BATLSA=:BATLSA,"
              + "BAABF2=:BAABF2,"
              + "BAZBEDKG=:BAZBEDKG,"
              + "BAZBEDMTR=:BAZBEDMTR,"
              + "BAFILLER=:BAFILLER"
              + " WHERE  "
              + "  BAMANDANT=:BAMANDANT AND BAAUFTYP=:BAAUFTYP AND BAAUFKRS=:BAAUFKRS AND BAAUFLFD=:BAAUFLFD AND BAAUFPOS=:BAAUFPOS AND BASA=:BASA AND BAPOS=:BAPOS";


                    or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = dwData["BAMANDANT"].ToString();
                    or1.Parameters.Add("BAAUFTYP", OracleType.NVarChar).Value = dwData["BAAUFTYP"].ToString();
                    or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = dwData["BAAUFKRS"].ToString();
                    or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = dwData["BAAUFLFD"].ToString();
                    or1.Parameters.Add("BAAUFPOS", OracleType.NVarChar).Value = dwData["BAAUFPOS"].ToString();
                    or1.Parameters.Add("BASA", OracleType.NVarChar).Value = dwData["BASA"].ToString();
                    or1.Parameters.Add("BAPOS", OracleType.NVarChar).Value = dwData["BAPOS"].ToString();
                    or1.Parameters.Add("BAAFOLGE", OracleType.NVarChar).Value = dwData["BAAFOLGE"].ToString();
                    or1.Parameters.Add("BADATVON", OracleType.NVarChar).Value = dwData["BADATVON"].ToString();
                    or1.Parameters.Add("BADATBIS", OracleType.NVarChar).Value = dwData["BADATBIS"].ToString();
                    or1.Parameters.Add("BAKART", OracleType.NVarChar).Value = dwData["BAKART"].ToString();
                    or1.Parameters.Add("BAKVAR", OracleType.NVarChar).Value = dwData["BAKVAR"].ToString();
                    or1.Parameters.Add("BAKFARBE", OracleType.NVarChar).Value = dwData["BAKFARBE"].ToString();
                    or1.Parameters.Add("BAMTR1", OracleType.NVarChar).Value = dwData["BAMTR1"].ToString();
                    or1.Parameters.Add("BAANZ1", OracleType.NVarChar).Value = dwData["BAANZ1"].ToString();
                    or1.Parameters.Add("BAMTR2", OracleType.NVarChar).Value = dwData["BAMTR2"].ToString();
                    or1.Parameters.Add("BAANZ2", OracleType.NVarChar).Value = dwData["BAANZ2"].ToString();
                    or1.Parameters.Add("BAMTR3", OracleType.NVarChar).Value = dwData["BAMTR3"].ToString();
                    or1.Parameters.Add("BAANZ3", OracleType.NVarChar).Value = dwData["BAANZ3"].ToString();
                    or1.Parameters.Add("BAMTR4", OracleType.NVarChar).Value = dwData["BAMTR4"].ToString();
                    or1.Parameters.Add("BAANZ4", OracleType.NVarChar).Value = dwData["BAANZ4"].ToString();
                    or1.Parameters.Add("BAMTR5", OracleType.NVarChar).Value = dwData["BAMTR5"].ToString();
                    or1.Parameters.Add("BAANZ5", OracleType.NVarChar).Value = dwData["BAANZ5"].ToString();
                    or1.Parameters.Add("BAMTR6", OracleType.NVarChar).Value = dwData["BAMTR6"].ToString();
                    or1.Parameters.Add("BAANZ6", OracleType.NVarChar).Value = dwData["BAANZ6"].ToString();
                    or1.Parameters.Add("BAMTR7", OracleType.NVarChar).Value = dwData["BAMTR7"].ToString();
                    or1.Parameters.Add("BAANZ7", OracleType.NVarChar).Value = dwData["BAANZ7"].ToString();
                    or1.Parameters.Add("BAERLKZ", OracleType.NVarChar).Value = dwData["BAERLKZ"].ToString();
                    or1.Parameters.Add("BABAUMART", OracleType.NVarChar).Value = dwData["BABAUMART"].ToString();
                    or1.Parameters.Add("BADRKZ", OracleType.NVarChar).Value = dwData["BADRKZ"].ToString();
                    or1.Parameters.Add("BADISPOKZ", OracleType.NVarChar).Value = dwData["BADISPOKZ"].ToString();
                    or1.Parameters.Add("BALO", OracleType.NVarChar).Value = dwData["BALO"].ToString();
                    or1.Parameters.Add("BALB", OracleType.NVarChar).Value = dwData["BALB"].ToString();
                    or1.Parameters.Add("BALP", OracleType.NVarChar).Value = dwData["BALP"].ToString();
                    or1.Parameters.Add("BAAUFBKZ", OracleType.NVarChar).Value = dwData["BAAUFBKZ"].ToString();
                    or1.Parameters.Add("BAURKVAR", OracleType.NVarChar).Value = dwData["BAURKVAR"].ToString();
                    or1.Parameters.Add("BAAENDZL", OracleType.NVarChar).Value = dwData["BAAENDZL"].ToString();
                    or1.Parameters.Add("BAAENDBEN", OracleType.NVarChar).Value = dwData["BAAENDBEN"].ToString();
                    or1.Parameters.Add("BAAENDDAT", OracleType.NVarChar).Value = dwData["BAAENDDAT"].ToString();
                    or1.Parameters.Add("BANEUBEN", OracleType.NVarChar).Value = dwData["BANEUBEN"].ToString();
                    or1.Parameters.Add("BANEUDAT", OracleType.NVarChar).Value = dwData["BANEUDAT"].ToString();
                    or1.Parameters.Add("BADOMKZ", OracleType.NVarChar).Value = dwData["BADOMKZ"].ToString();
                    or1.Parameters.Add("BABASMG", OracleType.NVarChar).Value = dwData["BABASMG"].ToString();
                    or1.Parameters.Add("BALLEIST", OracleType.NVarChar).Value = dwData["BALLEIST"].ToString();
                    or1.Parameters.Add("BARLEIST", OracleType.NVarChar).Value = dwData["BARLEIST"].ToString();
                    or1.Parameters.Add("BASCHIENE", OracleType.NVarChar).Value = dwData["BASCHIENE"].ToString();
                    or1.Parameters.Add("BATLPOS", OracleType.NVarChar).Value = dwData["BATLPOS"].ToString();
                    or1.Parameters.Add("BAINFOKZ", OracleType.NVarChar).Value = dwData["BAINFOKZ"].ToString();
                    or1.Parameters.Add("BAVARKZ", OracleType.NVarChar).Value = dwData["BAVARKZ"].ToString();
                    or1.Parameters.Add("BATLSA", OracleType.NVarChar).Value = dwData["BATLSA"].ToString();
                    or1.Parameters.Add("BAABF2", OracleType.NVarChar).Value = dwData["BAABF2"].ToString();
                    or1.Parameters.Add("BAZBEDKG", OracleType.NVarChar).Value = dwData["BAZBEDKG"].ToString();
                    or1.Parameters.Add("BAZBEDMTR", OracleType.NVarChar).Value = dwData["BAZBEDMTR"].ToString();
                    or1.Parameters.Add("BAFILLER", OracleType.NVarChar).Value = dwData["BAFILLER"].ToString();
                    break;
                case 2:
                    or1.CommandText = "UPDATE BAAUF SET "
              + "BAMTR2=:BAMTR2,"
              + "BAANZ2=:BAANZ2"
              + " WHERE  "
              + "  BAMANDANT=:BAMANDANT AND BAAUFTYP=:BAAUFTYP AND BAAUFKRS=:BAAUFKRS AND BAAUFLFD=:BAAUFLFD AND BAAUFPOS=:BAAUFPOS AND BASA=:BASA AND BAPOS=:BAPOS";
                    or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = dwData["BAMANDANT"].ToString();
                    or1.Parameters.Add("BAAUFTYP", OracleType.NVarChar).Value = dwData["BAAUFTYP"].ToString();
                    or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = dwData["BAAUFKRS"].ToString();
                    or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = dwData["BAAUFLFD"].ToString();
                    or1.Parameters.Add("BAAUFPOS", OracleType.NVarChar).Value = dwData["BAAUFPOS"].ToString();
                    or1.Parameters.Add("BASA", OracleType.NVarChar).Value = dwData["BASA"].ToString();
                    or1.Parameters.Add("BAPOS", OracleType.NVarChar).Value = dwData["BAPOS"].ToString();
                    or1.Parameters.Add("BAMTR2", OracleType.NVarChar).Value = dwData["BAMTR2"].ToString();
                    or1.Parameters.Add("BAANZ2", OracleType.NVarChar).Value = dwData["BAANZ2"].ToString();
                    break;
            }

            Connect2Proxy(or1);
        }
        public DataSet QueryBAAUF(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM  BAAUF"
                        + " WHERE "
                        + " BAMANDANT=:BAMANDANT AND BAAUFTYP=:BAAUFTYP AND BAAUFKRS=:BAAUFKRS AND BAAUFLFD=:BAAUFLFD AND BAAUFPOS=:BAAUFPOS"
                        + " AND BASA=:BASA AND BAPOS=:BAPOS";
                    or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = dwData["BAMANDANT"].ToString();
                    or1.Parameters.Add("BAAUFTYP", OracleType.NVarChar).Value = dwData["BAAUFTYP"].ToString();
                    or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = dwData["BAAUFKRS"].ToString();
                    or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = dwData["BAAUFLFD"].ToString();
                    or1.Parameters.Add("BAAUFPOS", OracleType.NVarChar).Value = dwData["BAAUFPOS"].ToString();
                    or1.Parameters.Add("BASA", OracleType.NVarChar).Value = dwData["BASA"].ToString();
                    or1.Parameters.Add("BAPOS", OracleType.NVarChar).Value = dwData["BAPOS"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM  BAAUF"
                        + " WHERE "
                        + " BAMANDANT=:BAMANDANT AND BAAUFTYP=:BAAUFTYP AND BAAUFKRS=:BAAUFKRS AND BAAUFLFD=:BAAUFLFD AND BAAUFPOS=:BAAUFPOS"
        ;
                    or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = dwData["BAMANDANT"].ToString();
                    or1.Parameters.Add("BAAUFTYP", OracleType.NVarChar).Value = dwData["BAAUFTYP"].ToString();
                    or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = dwData["BAAUFKRS"].ToString();
                    or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = dwData["BAAUFLFD"].ToString();
                    or1.Parameters.Add("BAAUFPOS", OracleType.NVarChar).Value = dwData["BAAUFPOS"].ToString();

                    break;
                case 3:
                    or1.CommandText = "SELECT * FROM  BAAUF"
                        + " WHERE "
                        + " BAMANDANT=:BAMANDANT  AND BAAUFKRS=:BAAUFKRS AND BAAUFLFD=:BAAUFLFD AND BAAUFPOS=:BAAUFPOS"
                        + "  AND BAPOS=:BAPOS";
                    or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = dwData["BAMANDANT"].ToString();
                    or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = dwData["BAAUFKRS"].ToString();
                    or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = dwData["BAAUFLFD"].ToString();
                    or1.Parameters.Add("BAAUFPOS", OracleType.NVarChar).Value = dwData["BAAUFPOS"].ToString();
                    or1.Parameters.Add("BAPOS", OracleType.NVarChar).Value = dwData["BAPOS"].ToString();
                    break;
                case 4:
                    or1.CommandText = "SELECT * FROM  BAAUF"
                        + " WHERE "
                        + " BAMANDANT=:BAMANDANT  AND BAAUFKRS=:BAAUFKRS AND BAAUFLFD=:BAAUFLFD "
        ;
                    or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = dwData["BAMANDANT"].ToString();
                    or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = dwData["BAAUFKRS"].ToString();
                    or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = dwData["BAAUFLFD"].ToString();
                    break;
                case 5:
                    or1.CommandText = "SELECT DISTINCT M.* FROM  BAAUF M JOIN ABPOS ON  BAMANDANT=ABPMANDANT  AND BAAUFKRS=ABPAUFKRS AND BAAUFLFD=ABPAUFLFD AND BAAUFPOS=ABPAUFPOS "
                        + " WHERE "
                        + " ABPMANDANT=:ABPMANDANT  AND ABPAUFKRS=:ABPAUFKRS AND ABPAUFLFD=:ABPAUFLFD ";
                    or1.Parameters.Add("ABPMANDANT", OracleType.NVarChar).Value = dwData["ABPMANDANT"].ToString();
                    or1.Parameters.Add("ABPAUFKRS", OracleType.NVarChar).Value = dwData["ABPAUFKRS"].ToString();
                    or1.Parameters.Add("ABPAUFLFD", OracleType.NVarChar).Value = dwData["ABPAUFLFD"].ToString();
                    break;
                case 6://通过织造单，找到对应的织轴需求
                    or1.CommandText = "SELECT ABPMANDANT,ABPAUFKRS,ABPAUFLFD,ABPAUFPOS FROM  BAAUF JOIN ABPOS ON BAMANDANT=ABPMANDANT AND  ABPART=BAKART AND ABPFARBE=BAKFARBE  AND RTRIM(ABPVAR)=RTRIM(BAKVAR)"
                        + " WHERE "
                        + "BASA=733 AND  BAMANDANT=:BAMANDANT  AND BAAUFKRS=:BAAUFKRS AND BAAUFLFD=:BAAUFLFD AND BAAUFPOS=:BAAUFPOS";
                    or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = dwData["ABPMANDANT"].ToString();
                    or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = dwData["ABPAUFKRS"].ToString();
                    or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = dwData["ABPAUFLFD"].ToString();
                    or1.Parameters.Add("BAAUFPOS", OracleType.NVarChar).Value = dwData["ABPAUFPOS"].ToString();
                    break;
                default:
                    break;
            }

            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "BAAUF";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
    }
}
